﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ETL;

namespace WPFCommonControl
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class SqlServerLoginControl : UserControl
    {
        public void SetServerName(string servername)
        {
            servername.判断参数是否合法();
            txtServername.Text = servername;
        }

        public class X_CollectionData
        {
            public string Server { get; set; }
            public string DbName { get; set; }
            public string TableName { get; set; }
            public string UID { get; set; }
            public string PWD { get; set; }
            public int Port { get; set; }
            public bool IsTrust { get; set; }
            public X_LoginSqlType CurType { get; set; }
        }
        /// <summary>
        /// Return Object 
        /// </summary>
        public X_CollectionData X_Result
        {
            get
            {
                int port;
                int.TryParse(txtPort.Text, out port);
                if (port == 0) port = 1433;

                X_CollectionData resultData = new X_CollectionData()
                {
                    Server = txtServername.Text,
                    DbName = txtDbName.Text,
                    TableName = string.Empty,
                    UID = txtUsername.Text,
                    PWD = passwordBox1.Password,
                    IsTrust = (bool)chkIsTrustedConn.IsChecked,
                    Port=port,
                    CurType = comboBox1.SelectedItem as X_LoginSqlType
                };

                return resultData;
            }
        }

        public class X_LoginSqlType
        {
            public string Name { get; set; }
            public CoreEA.LoginDbInfo.SqlServerVersionCollection CurSqlType { get; set; }
            public override string ToString()
            {
                return Name;
            }
        }

        public SqlServerLoginControl()
        {
            InitializeComponent();
            InitSelf();
#if DEBUG
            TestCode();
            
#endif
        }

        private void TestCode()
        {

        }


        private void InitSelf()
        {
            this.comboBox1.Items.Add(new X_LoginSqlType()
            {
                CurSqlType = CoreEA.LoginDbInfo.SqlServerVersionCollection.Local,
                Name = "Local"
            });

            this.comboBox1.Items.Add(new X_LoginSqlType()
            {
                CurSqlType = CoreEA.LoginDbInfo.SqlServerVersionCollection.SqlServer2000,
                Name = "Sql Server 2000"
            });

            this.comboBox1.Items.Add(new X_LoginSqlType()
            {
                CurSqlType = CoreEA.LoginDbInfo.SqlServerVersionCollection.OleDb,
                Name = "Ole DB"
            });

            this.comboBox1.Items.Add(new X_LoginSqlType()
            {
                CurSqlType = CoreEA.LoginDbInfo.SqlServerVersionCollection.SqlServer2005Express,
                Name = "Sql Server 2005 Express"
            });

            this.comboBox1.Items.Add(new X_LoginSqlType()
            {
                CurSqlType = CoreEA.LoginDbInfo.SqlServerVersionCollection.Standard,
                Name = "Standard"
            });


            this.comboBox1.Items.Add(new X_LoginSqlType()
            {
                CurSqlType = CoreEA.LoginDbInfo.SqlServerVersionCollection.AttachFile,
                Name = "Attach File"
            });

            this.comboBox1.SelectedIndex = 0;
        }
    }
}
